package com.sjx.boundarycallback.ui;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.sjx.boundarycallback.R;
import com.sjx.boundarycallback.adapter.FragmentAdapter;
import com.sjx.boundarycallback.databinding.ActivityTabLayoutBinding;
import com.sjx.boundarycallback.ui.fragment.AutoTextFragment;
import com.sjx.boundarycallback.ui.fragment.SecondFragment;
import com.sjx.boundarycallback.ui.fragment.ThirdFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * created by sjx on 6/1/22
 * TabLayout+ViewPager Activity
 */
public class TabLayoutActivity extends AppCompatActivity {

    private ActivityTabLayoutBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_tab_layout);
        FragmentManager fragmentManager = getSupportFragmentManager();
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new AutoTextFragment());
        fragments.add(new SecondFragment());
        fragments.add(new ThirdFragment());
        List<String> tabs = new ArrayList<>();
        tabs.add("首页");
        tabs.add("社区");
        tabs.add("新闻");
        FragmentAdapter fragmentAdapter = new
                FragmentAdapter(fragmentManager, fragments, tabs);
        ViewPager viewPager = findViewById(R.id.viewPager);
        viewPager.setAdapter(fragmentAdapter);
        TabLayout tabLayout = findViewById(R.id.tab);
        tabLayout.setupWithViewPager(viewPager);
    }
}